package com.xiaodu.acer.phoneplay.di.module;

import android.app.Application;
import android.os.Environment;

import com.xiaodu.acer.phoneplay.common.Constant;

import java.io.File;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import library.util.ACache;
import retrofit2.Retrofit;
import zlc.season.rxdownload2.RxDownload;

import static android.os.Environment.DIRECTORY_DOWNLOADS;

/**
 * @author 小杜 QQ:1392229149
 * @name phone
 * @class name：com.xiaodu.acer.phoneplay.d2.moudle
 * @class describe
 * @time 2017/12/16 21:26
 * @change
 * @chang time
 * @class describe
 */
@Module
public class DownLoadModule {

    @Provides
    @Singleton
    public RxDownload provideRxDownload(Application application, Retrofit retrofit, File file) {
        //保存下载路径
        ACache.get(application).put(Constant.APK_DOWNLOAD_DIR, file.getPath());

        return RxDownload.getInstance(application)
                .defaultSavePath(file.getPath())
                .retrofit(retrofit)
                .maxDownloadNumber(5)
                .maxThread(10);
    }

    @Provides
    @Singleton
    File provideFile() {
        return Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS);
    }


}

